TARGET = chess

CPP_DIRS = src

BUILD_DIR = build

CXX = g++

EMPTY = 
ATAB = $(EMPTY)	$(EMPTY)

CPP_SOURCE = $(foreach dir,$(CPP_DIRS),$(wildcard $(dir)/*.cpp))
OBJECT = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(CPP_SOURCE))
D_FILE = $(OBJECT:%.o=%.d)

INC = -Iinc

-include $(D_FILE)

$(BUILD_DIR):
	mkdir $(BUILD_DIR)
	mkdir $(sort $(dir $(OBJECT)))

$(BUILD_DIR)/%.o $(BUILD_DIR)/%.d &:%.cpp | $(BUILD_DIR)
	$(CXX) -c -MMD $< -o $(BUILD_DIR)/$*.o -MF $(BUILD_DIR)/$*.d $(INC)
	@echo "$(ATAB)$(CXX) -c $< -o $(BUILD_DIR)/$*.o $(INC)" >> $(BUILD_DIR)/$*.d

all: $(OBJECT)
	$(CXX) $(OBJECT) -o $(BUILD_DIR)/$(TARGET)

clean:
	@rm -rf $(BUILD_DIR)

debug:
	@gdb $(BUILD_DIR)/$(TARGET)

tags:
	@ctags-universal -R .

.PHONY: all clean debug tags
